capture log close
clear all
set maxvar 30000
set more off
pause off
# delimit;

/* 
Figure II
*/


local data "" ;
local output "" ;

local title_age18unfav "Age 18 medical review" ;
local ytitle_age18unfav "Fraction receiving (unfavorable) age 18 review" ;

local unit_wk "weekly" ;
local unit_mo "monthly" ;
local bw_wk = 60 ;
local bw_2wk = 60 ;
local bw_mo = 21 ;

local bw_mo_start = 18 ;
local int_mo = 6 ;
local int_wk = 12 ;
local int_2wk = 12 ;
local bwshort_wk = 12 ;
local bwshort_2wk = 12 ;
local bwshort_mo = 6 ;


/* RD graphs */
foreach sample in all { ;

foreach time in mo { ;

	use "prwora_crime_collapsemo_all.dta", clear ;		

	gen rv = dob`time'_run ;
	gen byte above_cutoff = (rv >= 0);
	gen rv_X_uc = rv * (1 - above_cutoff);
	gen rv_X_ac = rv * (above_cutoff);

	foreach var in 
			age18unfav
		{;
		twoway  (scatter age18_yes dob`time'_run if abs(dob`time'_run)<`bw_`time'' , mcolor(green) msymbol(Oh)) 
				(scatter n_`var' dob`time'_run if abs(dob`time'_run)<`bw_`time'', mcolor(red) msymbol(Th)) 
				, 
				title("`title_`var''", size(medsmall)) 
				xtitle("18th birthday relative to August 22, 1996 (months)", size(medsmall)) 
				ytitle("`ytitle_`var''", size(medsmall))
				xline(0) 
				xscale(r(-`bw_`time'' `bw_`time'') ) 
				xlab(-`bw_`time'_start'(`int_`time'')`bw_`time'_start')
				ylab(,nogrid)
				legend (order(1 "Age 18 review" 2 "Unfavorable age 18 review"))
				graphregion(color(white))
				bgcolor(white)
				;
		graph export "`output'/fig2.png", width(1000) height(750) replace ;
		pause ;
		};



} ;

} ;




